package com.moli.iov.protocol.model;



import java.io.Serializable;

import com.moli.iov.protocol.codec.DataDecoder;
import com.moli.iov.protocol.codec.Serialize;
import com.moli.iov.protocol.enums.DateTimeTag;
import com.moli.iov.util.ByteArrayUtil;



/**
 * 解析国标头+6字节采集时间的实体
 *
 * @ClassName UnixTimeReq
 * @author liweisong
 * @Date 2017年8月15日 上午9:50:47
 */
@Serialize(unit="byte",isBigEndian=true)
public class UnixTimeReq extends Header implements Serializable {

    /** 
     */
    private static final long serialVersionUID = 1L;
    /**
     * 报文上报时间
     */
    @Serialize(unit = "byte", offset = header_offset + 0, size = 6)
    public DateTimeTag dateTimeTag;

    public DateTimeTag getDateTimeTag() {
        return dateTimeTag;
    }

    public void setDateTimeTag(DateTimeTag dateTimeTag) {
        this.dateTimeTag = dateTimeTag;
    }

    /**
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("UnixTimeReq [dateTimeTag=");
        builder.append(dateTimeTag);
        builder.append("]");
        return builder.toString();
    }

    public static void main(String[] args) {
//        byte[] bytes = new byte[] {0x23, 0x23, 0x02, (byte) 0xfe, 0x4c, 0x43, 0x30, 0x43, 0x45, 0x34, 0x43, 0x42, 0x32,
//                0x47, 0x31, 0x30, 0x35, 0x36, 0x38, 0x34, 0x33, 0x01, 0x00, 0x66,
//                // 以上为头信息
//                 (byte) 16, (byte) 12, (byte) 02, (byte) 14, (byte) 07, (byte) 10,//采集时间
//                (byte) 0xf7 };
        String string = "23 23 01 fe 4c 42 39 4b 41 44 44 42 36 47 31 5a 33 30 35 37 38 01 00 27 11 08 0e 11 0c 26 00 01 38 39 38 36 30 32 42 33 32 32 31 35 33 30 30 33 30 35 37 38 31 31 71 77 65 16 12 02 14 07 10 b9";

//        "71 77 65 71 77 65"
//        byte[] bs = new byte[]{0x71};

        byte[] bytes = ByteArrayUtil.hexStringToBytes(string);
        System.out.println(bytes);
        UnixTimeReq unixTimeReq = new UnixTimeReq();
        DataDecoder<UnixTimeReq> decoder = new DataDecoder<>();
        try {
            decoder.decode(unixTimeReq, bytes);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

         System.out.println("---"+unixTimeReq.toString()+"--"+unixTimeReq.vin);
    }
}
